package com.zhxh.nzpos.login;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.goods.GoodsMainActivity;
import com.zhxh.nzpos.query.QueryManageActivity;
import com.zhxh.nzpos.sell.DealActivity;
import com.zhxh.nzpos.setting.SettingManageActivity;

/**
 * 系统主界面
 * 
 * @author wangzt
 * 
 */
public class MainActivity extends BaseActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initViews();
	}

	private void initViews() {
		GridView gridView = (GridView) findViewById(R.id.grid_main);

		// 生成上部的grid的对象
		ArrayList<HashMap<String, Object>> imagelist = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> map1 = new HashMap<String, Object>();
		map1.put("image", R.drawable.main_sell);
		map1.put("text", getResources().getString(R.string.main_sell_title));
		imagelist.add(map1);
		/*
		 * HashMap<String, Object> map2 = new HashMap<String, Object>();
		 * map2.put("image", R.drawable.main_stock); map2.put("text",
		 * getResources().getString(R.string.main_stock_title));
		 * imagelist.add(map2);
		 */
		/*
		 * HashMap<String, Object> map3 = new HashMap<String, Object>();
		 * map3.put("image", R.drawable.main_buyin); map3.put("text",
		 * getResources().getString(R.string.main_buyin_title));
		 * imagelist.add(map3);
		 */

		HashMap<String, Object> map4 = new HashMap<String, Object>();
		map4.put("image", R.drawable.main_query);
		map4.put("text", getResources().getString(R.string.main_query_title));
		imagelist.add(map4);
		HashMap<String, Object> map6 = new HashMap<String, Object>();
		map6.put("image", R.drawable.main_goods);
		map6.put("text", getResources().getString(R.string.main_goods_title));
		imagelist.add(map6);
		HashMap<String, Object> map7 = new HashMap<String, Object>();
		map7.put("image", R.drawable.main_setting);
		map7.put("text", getResources().getString(R.string.main_setting_title));
		imagelist.add(map7);

		ImageAdapter simpleAdapter = new ImageAdapter(this, imagelist,
				R.layout.compose_grid_item, new String[] { "image", "text" },
				new int[] { R.id.compose_grid_image, R.id.compose_grid_text });

		gridView.setAdapter(simpleAdapter);

		gridView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				Intent intent = new Intent();

				switch (pos) {
				case 0:
					intent
							.setClass(getApplicationContext(),
									DealActivity.class);
					startActivity(intent);
					break;
				case 1:
					intent.setClass(getApplicationContext(),
							QueryManageActivity.class);
					startActivity(intent);
					break;
				case 2:
					intent.setClass(getApplicationContext(),
							GoodsMainActivity.class);
					startActivity(intent);
					break;
				case 3:
					intent.setClass(getApplicationContext(),
							SettingManageActivity.class);
					startActivity(intent);
					break;
				}
			}
		});

		/*
		 * GridView gridView_below = (GridView)
		 * findViewById(R.id.grid_main_second);
		 * 
		 * //生成下排三个 ArrayList<HashMap<String, Object>> imagelist2 = new
		 * ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map5 =
		 * new HashMap<String, Object>(); map5.put("image",
		 * R.drawable.main_member); map5.put("text",
		 * getResources().getString(R.string.main_member_title));
		 * imagelist2.add(map5); HashMap<String, Object> map6 = new
		 * HashMap<String, Object>(); map6.put("image", R.drawable.main_goods);
		 * map6.put("text",
		 * getResources().getString(R.string.main_goods_title));
		 * imagelist2.add(map6); HashMap<String, Object> map7 = new
		 * HashMap<String, Object>(); map7.put("image",
		 * R.drawable.main_setting); map7.put("text",
		 * getResources().getString(R.string.main_setting_title));
		 * imagelist2.add(map7);
		 * 
		 * 
		 * ImageAdapter simpleAdapter2 = new ImageAdapter(this, imagelist2,
		 * R.layout.compose_grid_item, new String[] { "image", "text" }, new
		 * int[] { R.id.compose_grid_image, R.id.compose_grid_text });
		 * gridView_below.setAdapter(simpleAdapter2);
		 * 
		 * 
		 * gridView_below.setOnItemClickListener(new OnItemClickListener() {
		 * public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long
		 * arg3) { Intent intent = new Intent(); switch (pos) { case 0:
		 * intent.setClass(getApplicationContext(), MemberManageActivity.class);
		 * startActivity(intent); break; case 1:
		 * intent.setClass(getApplicationContext(), GoodsMainActivity.class);
		 * startActivity(intent); break; case 2:
		 * intent.setClass(getApplicationContext(),
		 * SettingManageActivity.class); startActivity(intent); break; } } });
		 */
	}

}
